package cn.bobohost.crmrbac.web.controller;

import cn.bobohost.crmrbac.pojo.po.Department;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/thymeleaf")
@Slf4j
public class ThymeleafController {

    @GetMapping("/sayhi")
    public String sayHi(Model model){
        log.debug("--------------------------------------------------sayhi");
        //目标：将helloworld填充到模版中并显示

        //准备数据
        model.addAttribute("message","hello World");


        //转发到view，模版
        return "thymeleaf/01_hello";
    }

    @GetMapping("/str")
    public String str(Model model){
        //给model添加数据 --多个值可以写多个
        model.addAttribute("name", "Rose");
        model.addAttribute("age", 18);
        return "thymeleaf/02_str";
    }

    @GetMapping("/javabean")
    public String javabean(Model model){
        //目标：给model放进去一个javabena对象，模版引擎进行渲染

        Department department =new Department(123,"KFB","开发部");


        model.addAttribute("department",department);

        return "thymeleaf/03_javabean";


    }


    @GetMapping("/list")
    public String list(Model model){
        //目标：测试list渲染
        //1. 简单值列表
        List<String> strList =new ArrayList<>();
        strList.add("张三");
        strList.add("李四");
        strList.add("王五");

        model.addAttribute("strList",strList);


        //2.javabean的列表
        List<Department> departmentList =List.of(
            new Department(1,"KFB","开发部"),
            new Department(2,"HR","人事部"),
            new Department(3,"QA","测试部")
        );


        model.addAttribute("departmentList",departmentList);

        //转发到模版视图
        return "thymeleaf/04_list";


    }


    @GetMapping("/map")
    public String map(Model model){
        //目标：测试map渲染

        Map<String,Object> map =Map.of(
                "name","Rose",
                "age",18,
                "memo","美女一枚"
        );

        model.addAttribute("map",map);


        return "thymeleaf/05_map";
    }

    @GetMapping("/star")
    public String star(Model model){
        //目标：测试星号表达式
        Department department =new Department(123,"KFB","开发部");


        model.addAttribute("department",department);

        return "thymeleaf/06_star";

    }

    @GetMapping("/msg")
    public String msg(Model model){

        return "thymeleaf/07_msg";

    }



}
